#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std; 

#define N 5010

struct blk {
	int w, l; 
}; 

vector<blk> b; 
int n;

bool cmp(blk &a, blk &b)
{
	if (a.w>b.w) 
		return true; 
	if (a.w==b.w && a.l>b.l)
		return true; 
	return false; 
}

int main()
{
	vector<blk>::iterator it, p; 
	int r;
	scanf("%d", &n); 
	for (int i=0; i<n; i++) {
		int w, l; 
		scanf("%d %d", &w, &l); 
		b.push_back((blk){w, l}); 
	}
	sort(b.begin(), b.end(), cmp); 
	printf("---\n"); 
	
	for (p=b.begin(); p!=b.end(); p++) 
		printf(" %d %d\n", p->w, p->l); 
	
	r = 0; 
	while (b.size()>0) {
		int w, l; 
		r++; 
		it = b.begin(); 
		w = it->w;
		l = it->l; 
		p = it+1; 
		b.erase(it); 

		printf("-----\n"); 
		for (p=b.begin(); p!=b.end(); p++) 
			printf(" %d %d\n", p->w, p->l); 
		printf("====\n"); 
		printf("begin:\n"); 
		printf("  %d %d\n", w, l); 
		while (true) {
			if (p==b.end()) {
				break; 
			}
			if (p->w>w || p->l>l) {
				p++; 
				continue; 
			} else {
				it = p; 
				w = it->w;
				l = it->l; 
				printf("  %d %d\n", w, l); 
				p = it+1; 
				b.erase(it); 
			}
		}
	}
	printf("%d\n", r); 
	return 0; 
}




